<?php

namespace App\Models;

use Illuminate\Database\Eloquent\SoftDeletes;

class ProjectType extends Model
{
    use SoftDeletes;

    protected $dates = ['deleted_at'];

    protected $guarded = [];

    public function projects()
    {
        return $this->hasMany(Project::class, "project_type_id", "id");
    }

    public function getTypeList($isCount = false)
    {
        $query = $this->select("id", "project_type_name");
        return $isCount
            ? $query->withCount(["projects"])->enable()->get()->toArray()
            : $query->enable()->get()->toArray();
    }

    public function changeEnable($id, $status)
    {
        return $this->where("id", $id)->update(["is_enable" => $status]);
    }
}
